/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.portlet.service.persistence;

import com.liferay.portal.NoSuchModelException;
import com.liferay.portal.kernel.bean.BeanReference;
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
import com.liferay.portal.kernel.dao.jdbc.RowMapper;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.SQLQuery;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.BatchSessionUtil;
import com.liferay.portal.service.persistence.ResourcePersistence;
import com.liferay.portal.service.persistence.UserPersistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import com.portlet.NoSuchquycachSPException;

import com.portlet.model.impl.quycachSPImpl;
import com.portlet.model.impl.quycachSPModelImpl;
import com.portlet.model.quycachSP;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The persistence implementation for the quycach s p service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author Thi
 * @see quycachSPPersistence
 * @see quycachSPUtil
 * @generated
 */
public class quycachSPPersistenceImpl extends BasePersistenceImpl<quycachSP>
	implements quycachSPPersistence {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. Always use {@link quycachSPUtil} to access the quycach s p persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
	 */
	public static final String FINDER_CLASS_NAME_ENTITY = quycachSPImpl.class.getName();
	public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List1";
	public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List2";
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(quycachSPModelImpl.ENTITY_CACHE_ENABLED,
			quycachSPModelImpl.FINDER_CACHE_ENABLED, quycachSPImpl.class,
			FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(quycachSPModelImpl.ENTITY_CACHE_ENABLED,
			quycachSPModelImpl.FINDER_CACHE_ENABLED, quycachSPImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(quycachSPModelImpl.ENTITY_CACHE_ENABLED,
			quycachSPModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);

	/**
	 * Caches the quycach s p in the entity cache if it is enabled.
	 *
	 * @param quycachSP the quycach s p
	 */
	public void cacheResult(quycachSP quycachSP) {
		EntityCacheUtil.putResult(quycachSPModelImpl.ENTITY_CACHE_ENABLED,
			quycachSPImpl.class, quycachSP.getPrimaryKey(), quycachSP);

		quycachSP.resetOriginalValues();
	}

	/**
	 * Caches the quycach s ps in the entity cache if it is enabled.
	 *
	 * @param quycachSPs the quycach s ps
	 */
	public void cacheResult(List<quycachSP> quycachSPs) {
		for (quycachSP quycachSP : quycachSPs) {
			if (EntityCacheUtil.getResult(
						quycachSPModelImpl.ENTITY_CACHE_ENABLED,
						quycachSPImpl.class, quycachSP.getPrimaryKey()) == null) {
				cacheResult(quycachSP);
			}
			else {
				quycachSP.resetOriginalValues();
			}
		}
	}

	/**
	 * Clears the cache for all quycach s ps.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache() {
		if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
			CacheRegistryUtil.clear(quycachSPImpl.class.getName());
		}

		EntityCacheUtil.clearCache(quycachSPImpl.class.getName());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	/**
	 * Clears the cache for the quycach s p.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache(quycachSP quycachSP) {
		EntityCacheUtil.removeResult(quycachSPModelImpl.ENTITY_CACHE_ENABLED,
			quycachSPImpl.class, quycachSP.getPrimaryKey());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@Override
	public void clearCache(List<quycachSP> quycachSPs) {
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		for (quycachSP quycachSP : quycachSPs) {
			EntityCacheUtil.removeResult(quycachSPModelImpl.ENTITY_CACHE_ENABLED,
				quycachSPImpl.class, quycachSP.getPrimaryKey());
		}
	}

	/**
	 * Creates a new quycach s p with the primary key. Does not add the quycach s p to the database.
	 *
	 * @param maQC the primary key for the new quycach s p
	 * @return the new quycach s p
	 */
	public quycachSP create(String maQC) {
		quycachSP quycachSP = new quycachSPImpl();

		quycachSP.setNew(true);
		quycachSP.setPrimaryKey(maQC);

		return quycachSP;
	}

	/**
	 * Removes the quycach s p with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param maQC the primary key of the quycach s p
	 * @return the quycach s p that was removed
	 * @throws com.portlet.NoSuchquycachSPException if a quycach s p with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public quycachSP remove(String maQC)
		throws NoSuchquycachSPException, SystemException {
		return remove((Serializable)maQC);
	}

	/**
	 * Removes the quycach s p with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param primaryKey the primary key of the quycach s p
	 * @return the quycach s p that was removed
	 * @throws com.portlet.NoSuchquycachSPException if a quycach s p with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public quycachSP remove(Serializable primaryKey)
		throws NoSuchquycachSPException, SystemException {
		Session session = null;

		try {
			session = openSession();

			quycachSP quycachSP = (quycachSP)session.get(quycachSPImpl.class,
					primaryKey);

			if (quycachSP == null) {
				if (_log.isWarnEnabled()) {
					_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
				}

				throw new NoSuchquycachSPException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
					primaryKey);
			}

			return remove(quycachSP);
		}
		catch (NoSuchquycachSPException nsee) {
			throw nsee;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	@Override
	protected quycachSP removeImpl(quycachSP quycachSP)
		throws SystemException {
		quycachSP = toUnwrappedModel(quycachSP);

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.delete(session, quycachSP);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		clearCache(quycachSP);

		return quycachSP;
	}

	@Override
	public quycachSP updateImpl(com.portlet.model.quycachSP quycachSP,
		boolean merge) throws SystemException {
		quycachSP = toUnwrappedModel(quycachSP);

		boolean isNew = quycachSP.isNew();

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.update(session, quycachSP, merge);

			quycachSP.setNew(false);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

		if (isNew) {
			FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
		}

		EntityCacheUtil.putResult(quycachSPModelImpl.ENTITY_CACHE_ENABLED,
			quycachSPImpl.class, quycachSP.getPrimaryKey(), quycachSP);

		return quycachSP;
	}

	protected quycachSP toUnwrappedModel(quycachSP quycachSP) {
		if (quycachSP instanceof quycachSPImpl) {
			return quycachSP;
		}

		quycachSPImpl quycachSPImpl = new quycachSPImpl();

		quycachSPImpl.setNew(quycachSP.isNew());
		quycachSPImpl.setPrimaryKey(quycachSP.getPrimaryKey());

		quycachSPImpl.setMaQC(quycachSP.getMaQC());
		quycachSPImpl.setTenQC(quycachSP.getTenQC());

		return quycachSPImpl;
	}

	/**
	 * Returns the quycach s p with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
	 *
	 * @param primaryKey the primary key of the quycach s p
	 * @return the quycach s p
	 * @throws com.liferay.portal.NoSuchModelException if a quycach s p with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public quycachSP findByPrimaryKey(Serializable primaryKey)
		throws NoSuchModelException, SystemException {
		return findByPrimaryKey((String)primaryKey);
	}

	/**
	 * Returns the quycach s p with the primary key or throws a {@link com.portlet.NoSuchquycachSPException} if it could not be found.
	 *
	 * @param maQC the primary key of the quycach s p
	 * @return the quycach s p
	 * @throws com.portlet.NoSuchquycachSPException if a quycach s p with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public quycachSP findByPrimaryKey(String maQC)
		throws NoSuchquycachSPException, SystemException {
		quycachSP quycachSP = fetchByPrimaryKey(maQC);

		if (quycachSP == null) {
			if (_log.isWarnEnabled()) {
				_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + maQC);
			}

			throw new NoSuchquycachSPException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
				maQC);
		}

		return quycachSP;
	}

	/**
	 * Returns the quycach s p with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param primaryKey the primary key of the quycach s p
	 * @return the quycach s p, or <code>null</code> if a quycach s p with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public quycachSP fetchByPrimaryKey(Serializable primaryKey)
		throws SystemException {
		return fetchByPrimaryKey((String)primaryKey);
	}

	/**
	 * Returns the quycach s p with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param maQC the primary key of the quycach s p
	 * @return the quycach s p, or <code>null</code> if a quycach s p with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public quycachSP fetchByPrimaryKey(String maQC) throws SystemException {
		quycachSP quycachSP = (quycachSP)EntityCacheUtil.getResult(quycachSPModelImpl.ENTITY_CACHE_ENABLED,
				quycachSPImpl.class, maQC);

		if (quycachSP == _nullquycachSP) {
			return null;
		}

		if (quycachSP == null) {
			Session session = null;

			boolean hasException = false;

			try {
				session = openSession();

				quycachSP = (quycachSP)session.get(quycachSPImpl.class, maQC);
			}
			catch (Exception e) {
				hasException = true;

				throw processException(e);
			}
			finally {
				if (quycachSP != null) {
					cacheResult(quycachSP);
				}
				else if (!hasException) {
					EntityCacheUtil.putResult(quycachSPModelImpl.ENTITY_CACHE_ENABLED,
						quycachSPImpl.class, maQC, _nullquycachSP);
				}

				closeSession(session);
			}
		}

		return quycachSP;
	}

	/**
	 * Returns all the quycach s ps.
	 *
	 * @return the quycach s ps
	 * @throws SystemException if a system exception occurred
	 */
	public List<quycachSP> findAll() throws SystemException {
		return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the quycach s ps.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of quycach s ps
	 * @param end the upper bound of the range of quycach s ps (not inclusive)
	 * @return the range of quycach s ps
	 * @throws SystemException if a system exception occurred
	 */
	public List<quycachSP> findAll(int start, int end)
		throws SystemException {
		return findAll(start, end, null);
	}

	/**
	 * Returns an ordered range of all the quycach s ps.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of quycach s ps
	 * @param end the upper bound of the range of quycach s ps (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of quycach s ps
	 * @throws SystemException if a system exception occurred
	 */
	public List<quycachSP> findAll(int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = new Object[] { start, end, orderByComparator };

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
			finderArgs = FINDER_ARGS_EMPTY;
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
			finderArgs = new Object[] { start, end, orderByComparator };
		}

		List<quycachSP> list = (List<quycachSP>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;
			String sql = null;

			if (orderByComparator != null) {
				query = new StringBundler(2 +
						(orderByComparator.getOrderByFields().length * 3));

				query.append(_SQL_SELECT_QUYCACHSP);

				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);

				sql = query.toString();
			}
			else {
				sql = _SQL_SELECT_QUYCACHSP;
			}

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				if (orderByComparator == null) {
					list = (List<quycachSP>)QueryUtil.list(q, getDialect(),
							start, end, false);

					Collections.sort(list);
				}
				else {
					list = (List<quycachSP>)QueryUtil.list(q, getDialect(),
							start, end);
				}
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Removes all the quycach s ps from the database.
	 *
	 * @throws SystemException if a system exception occurred
	 */
	public void removeAll() throws SystemException {
		for (quycachSP quycachSP : findAll()) {
			remove(quycachSP);
		}
	}

	/**
	 * Returns the number of quycach s ps.
	 *
	 * @return the number of quycach s ps
	 * @throws SystemException if a system exception occurred
	 */
	public int countAll() throws SystemException {
		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
				FINDER_ARGS_EMPTY, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(_SQL_COUNT_QUYCACHSP);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
					FINDER_ARGS_EMPTY, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns all the nlhassps associated with the quycach s p.
	 *
	 * @param pk the primary key of the quycach s p
	 * @return the nlhassps associated with the quycach s p
	 * @throws SystemException if a system exception occurred
	 */
	public List<com.portlet.model.nlhassp> getnlhassps(String pk)
		throws SystemException {
		return getnlhassps(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
	}

	/**
	 * Returns a range of all the nlhassps associated with the quycach s p.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the quycach s p
	 * @param start the lower bound of the range of quycach s ps
	 * @param end the upper bound of the range of quycach s ps (not inclusive)
	 * @return the range of nlhassps associated with the quycach s p
	 * @throws SystemException if a system exception occurred
	 */
	public List<com.portlet.model.nlhassp> getnlhassps(String pk, int start,
		int end) throws SystemException {
		return getnlhassps(pk, start, end, null);
	}

	public static final FinderPath FINDER_PATH_GET_NLHASSPS = new FinderPath(com.portlet.model.impl.nlhasspModelImpl.ENTITY_CACHE_ENABLED,
			com.portlet.model.impl.nlhasspModelImpl.FINDER_CACHE_ENABLED,
			com.portlet.model.impl.nlhasspImpl.class,
			com.portlet.service.persistence.nlhasspPersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"getnlhassps",
			new String[] {
				String.class.getName(), "java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});

	static {
		FINDER_PATH_GET_NLHASSPS.setCacheKeyGeneratorCacheName(null);
	}

	/**
	 * Returns an ordered range of all the nlhassps associated with the quycach s p.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the quycach s p
	 * @param start the lower bound of the range of quycach s ps
	 * @param end the upper bound of the range of quycach s ps (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of nlhassps associated with the quycach s p
	 * @throws SystemException if a system exception occurred
	 */
	public List<com.portlet.model.nlhassp> getnlhassps(String pk, int start,
		int end, OrderByComparator orderByComparator) throws SystemException {
		Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };

		List<com.portlet.model.nlhassp> list = (List<com.portlet.model.nlhassp>)FinderCacheUtil.getResult(FINDER_PATH_GET_NLHASSPS,
				finderArgs, this);

		if (list == null) {
			Session session = null;

			try {
				session = openSession();

				String sql = null;

				if (orderByComparator != null) {
					sql = _SQL_GETNLHASSPS.concat(ORDER_BY_CLAUSE)
										  .concat(orderByComparator.getOrderBy());
				}
				else {
					sql = _SQL_GETNLHASSPS;
				}

				SQLQuery q = session.createSQLQuery(sql);

				q.addEntity("congty_nlhassp",
					com.portlet.model.impl.nlhasspImpl.class);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				list = (List<com.portlet.model.nlhassp>)QueryUtil.list(q,
						getDialect(), start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_GET_NLHASSPS,
						finderArgs);
				}
				else {
					nlhasspPersistence.cacheResult(list);

					FinderCacheUtil.putResult(FINDER_PATH_GET_NLHASSPS,
						finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	public static final FinderPath FINDER_PATH_GET_NLHASSPS_SIZE = new FinderPath(com.portlet.model.impl.nlhasspModelImpl.ENTITY_CACHE_ENABLED,
			com.portlet.model.impl.nlhasspModelImpl.FINDER_CACHE_ENABLED,
			com.portlet.model.impl.nlhasspImpl.class,
			com.portlet.service.persistence.nlhasspPersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"getnlhasspsSize", new String[] { String.class.getName() });

	static {
		FINDER_PATH_GET_NLHASSPS_SIZE.setCacheKeyGeneratorCacheName(null);
	}

	/**
	 * Returns the number of nlhassps associated with the quycach s p.
	 *
	 * @param pk the primary key of the quycach s p
	 * @return the number of nlhassps associated with the quycach s p
	 * @throws SystemException if a system exception occurred
	 */
	public int getnlhasspsSize(String pk) throws SystemException {
		Object[] finderArgs = new Object[] { pk };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_NLHASSPS_SIZE,
				finderArgs, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				SQLQuery q = session.createSQLQuery(_SQL_GETNLHASSPSSIZE);

				q.addScalar(COUNT_COLUMN_NAME,
					com.liferay.portal.kernel.dao.orm.Type.LONG);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_GET_NLHASSPS_SIZE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	public static final FinderPath FINDER_PATH_CONTAINS_NLHASSP = new FinderPath(com.portlet.model.impl.nlhasspModelImpl.ENTITY_CACHE_ENABLED,
			com.portlet.model.impl.nlhasspModelImpl.FINDER_CACHE_ENABLED,
			com.portlet.model.impl.nlhasspImpl.class,
			com.portlet.service.persistence.nlhasspPersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"containsnlhassp",
			new String[] { String.class.getName(), Long.class.getName() });

	/**
	 * Returns <code>true</code> if the nlhassp is associated with the quycach s p.
	 *
	 * @param pk the primary key of the quycach s p
	 * @param nlhasspPK the primary key of the nlhassp
	 * @return <code>true</code> if the nlhassp is associated with the quycach s p; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsnlhassp(String pk, long nlhasspPK)
		throws SystemException {
		Object[] finderArgs = new Object[] { pk, nlhasspPK };

		Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_NLHASSP,
				finderArgs, this);

		if (value == null) {
			try {
				value = Boolean.valueOf(containsnlhassp.contains(pk, nlhasspPK));
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (value == null) {
					value = Boolean.FALSE;
				}

				FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_NLHASSP,
					finderArgs, value);
			}
		}

		return value.booleanValue();
	}

	/**
	 * Returns <code>true</code> if the quycach s p has any nlhassps associated with it.
	 *
	 * @param pk the primary key of the quycach s p to check for associations with nlhassps
	 * @return <code>true</code> if the quycach s p has any nlhassps associated with it; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsnlhassps(String pk) throws SystemException {
		if (getnlhasspsSize(pk) > 0) {
			return true;
		}
		else {
			return false;
		}
	}

	/**
	 * Initializes the quycach s p persistence.
	 */
	public void afterPropertiesSet() {
		String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
					com.liferay.util.service.ServiceProps.get(
						"value.object.listener.com.portlet.model.quycachSP")));

		if (listenerClassNames.length > 0) {
			try {
				List<ModelListener<quycachSP>> listenersList = new ArrayList<ModelListener<quycachSP>>();

				for (String listenerClassName : listenerClassNames) {
					Class<?> clazz = getClass();

					listenersList.add((ModelListener<quycachSP>)InstanceFactory.newInstance(
							clazz.getClassLoader(), listenerClassName));
				}

				listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
			}
			catch (Exception e) {
				_log.error(e);
			}
		}

		containsnlhassp = new Containsnlhassp();
	}

	public void destroy() {
		EntityCacheUtil.removeCache(quycachSPImpl.class.getName());
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@BeanReference(type = nguyenlieuPersistence.class)
	protected nguyenlieuPersistence nguyenlieuPersistence;
	@BeanReference(type = nlhasspPersistence.class)
	protected nlhasspPersistence nlhasspPersistence;
	@BeanReference(type = quycachSPPersistence.class)
	protected quycachSPPersistence quycachSPPersistence;
	@BeanReference(type = ResourcePersistence.class)
	protected ResourcePersistence resourcePersistence;
	@BeanReference(type = UserPersistence.class)
	protected UserPersistence userPersistence;
	protected Containsnlhassp containsnlhassp;

	protected class Containsnlhassp {
		protected Containsnlhassp() {
			_mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
					_SQL_CONTAINSNLHASSP,
					new int[] { java.sql.Types.VARCHAR, java.sql.Types.BIGINT },
					RowMapper.COUNT);
		}

		protected boolean contains(String maQC, long maNLSP) {
			List<Integer> results = _mappingSqlQuery.execute(new Object[] {
						maQC, new Long(maNLSP)
					});

			if (results.size() > 0) {
				Integer count = results.get(0);

				if (count.intValue() > 0) {
					return true;
				}
			}

			return false;
		}

		private MappingSqlQuery<Integer> _mappingSqlQuery;
	}

	private static final String _SQL_SELECT_QUYCACHSP = "SELECT quycachSP FROM quycachSP quycachSP";
	private static final String _SQL_COUNT_QUYCACHSP = "SELECT COUNT(quycachSP) FROM quycachSP quycachSP";
	private static final String _SQL_GETNLHASSPS = "SELECT {congty_nlhassp.*} FROM congty_nlhassp INNER JOIN congty_quycachSP ON (congty_quycachSP.maQC = congty_nlhassp.maQC) WHERE (congty_quycachSP.maQC = ?)";
	private static final String _SQL_GETNLHASSPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM congty_nlhassp WHERE maQC = ?";
	private static final String _SQL_CONTAINSNLHASSP = "SELECT COUNT(*) AS COUNT_VALUE FROM congty_nlhassp WHERE maQC = ? AND maNLSP = ?";
	private static final String _ORDER_BY_ENTITY_ALIAS = "quycachSP.";
	private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No quycachSP exists with the primary key ";
	private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
				PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
	private static Log _log = LogFactoryUtil.getLog(quycachSPPersistenceImpl.class);
	private static quycachSP _nullquycachSP = new quycachSPImpl() {
			@Override
			public Object clone() {
				return this;
			}

			@Override
			public CacheModel<quycachSP> toCacheModel() {
				return _nullquycachSPCacheModel;
			}
		};

	private static CacheModel<quycachSP> _nullquycachSPCacheModel = new CacheModel<quycachSP>() {
			public quycachSP toEntityModel() {
				return _nullquycachSP;
			}
		};
}